package com.tm.servicemsm.utils;

import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Random;

/**
 * 2024/7/15 RandomUtil Cjj  10:17
 */
public class RandomUtil {
    private static final Random random=new Random();
    private static final DecimalFormat fourdf=new DecimalFormat("0000");
    private static final DecimalFormat sixdf=new DecimalFormat("0000");
    private static String getFourBitRandom(){return  fourdf.format(random.nextInt(10000));}
    public static String getSixBitRandom(){return sixdf.format(random.nextInt(1000000));}

    /**
     * 给定数组,抽取n个数据
     *
     * @return
     */
    public static ArrayList getRandom(List list, int n){
        Random random = new Random();
        HashMap<Object, Object> map = new HashMap<>();

        //生成随机数字并存入HashMap
        for (int i = 0; i <list.size() ; i++) {
            int number = random.nextInt(100) + 1;
            map.put(number,i);
        }

        //从HashMap导入数组
        Object[] objects = map.values().toArray();
        ArrayList r = new ArrayList<>();

        //遍历数组并打印数据
/*        for (int i = 0; i <n ; i++) {
            r.add(list.get((Integer) objects[i])
            System.out.println(list.get(Integer.parseInt( objects[i]+"\t"))
        }
        System.out.println("\n");*/
        return r;
    }
}
